package com.concurrent.threadPoolTest;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: zhouyang
 * @descrpition:
 * @time: 2019-05-13 14:29
 */
@Slf4j
public class ThreadPoolTest2 {
    public static void main(String[] args) {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);//3个线程
//        executorService.schedule(()->{
//            log.info("running");
//        },3, TimeUnit.SECONDS);//延迟三秒执行

        executorService.scheduleAtFixedRate(()->{
            log.info("running");
        },1,3,TimeUnit.SECONDS);//每三秒执行一次 只要不关闭线程池
        //类似Timer类 定时执行某些任务
        //executorService.shutdown();
    }
}
